﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InvoiceManagement.Support;
using System.Configuration;
using MySql.Data.MySqlClient;

namespace InvoiceManagement.Forms
{
  public partial class ViewEmployeeDetails : Form
  {
    private string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];


    public ViewEmployeeDetails()
    {
      InitializeComponent();
      DatabaseOperations.Initialize(this.connectionString);
    }

    private void OnFormLoad(object sender, EventArgs e)
    {
      string query = "Select EmployeeNumber from EmployeeDetails";
      List<string> lst = DatabaseOperations.ExecuteQueryWithParametersGetOrdinalList(query, "EmployeeNumber");
      this.lstEmployeeID.Items.AddRange(lst.ToArray());
      
      if (this.lstEmployeeID.Items.Count > 0)
        this.lstEmployeeID.SelectedIndex = 0;
    }

    private void lstEmployeeID_SelectedIndexChanged(object sender, EventArgs e)
    {
      string query = "Select * from EmployeeDetails Where EmployeeNumber = @EmployeeNumber";
      List<MySqlParameter> parameters = new List<MySqlParameter>();
      parameters.Add(new MySqlParameter("@EmployeeNumber", this.lstEmployeeID.Text));

      List<string> result = DatabaseOperations.ExecuteQueryWithParametersGetItem(query, parameters);

      this.lblEmployeeName.Text = result[0];
      this.lblEmployeeNumber.Text = result[1];
      this.lblMobileNumber.Text = result[2];
      this.lblQualification.Text = result[3];
      this.lblDesignation.Text = result[4];
      this.lblAddress.Text = result[5];
    }
  }
}
